﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace RenameSubtitles
{
    class Program
    {

        static void Test1()
        {
            RenameSubtitlesJob job = new RenameSubtitlesJob("D:\\Temp\\videos", true, true);
            job.Start();
        }
        static void Main(string[] args)
        {            
            string path= null;
            bool recursive = false;

            if (args.Length >= 1)
            {
                foreach (string arg in args)
                {
                    if (arg.Equals("-h", StringComparison.CurrentCultureIgnoreCase) || arg.Equals("/h", StringComparison.CurrentCultureIgnoreCase))
                    {
                        ShowHelp();
                        return;
                    }
                    else if (arg.Equals("-R", StringComparison.CurrentCultureIgnoreCase) || arg.Equals("/r", StringComparison.CurrentCultureIgnoreCase))
                    {
                        recursive= true;
                    }
                    else
                    {
                        path = arg;
                    }
                }
            }
            
            if (string.IsNullOrEmpty(path))
                path= ".";

            RenameSubtitlesJob job = new RenameSubtitlesJob(path, true, recursive);            
            job.Start();
        }

        private static void SetupTest()
        {
            string path = "D:\\Temp\\videos";
            
            CreateEmptyFile(path, "Pepepe 1x01 pepito.avi");
            CreateEmptyFile(path, "Pepepe 1x02 pepito.mkv");
            CreateEmptyFile(path, "Pepepe 1x03 pepito.mp4");
            CreateEmptyFile(path, "Pepepe 1x04 pepito.avi");

            CreateEmptyFile(path, "Pepe 1x01 .srt");
            CreateEmptyFile(path, "Pepe 1x02 pito.srt");
            CreateEmptyFile(path, "Pepee 1x03 pito.srt");
            CreateEmptyFile(path, "Pepe 1x04 ppito.srt");

            path = "D:\\Temp\\videos\\tb";

            CreateEmptyFile(path, "TBpe 1x01 pepito.avi");
            CreateEmptyFile(path, "TBpe 1x02 pepito.mkv");
            CreateEmptyFile(path, "TBpe 1x03 pepito.mp4");
            CreateEmptyFile(path, "TBpe 1x04 pepito.avi");

            CreateEmptyFile(path, "TB 1x01 .srt");
            CreateEmptyFile(path, "TB 1x02 pito.srt");
            CreateEmptyFile(path, "TBe 1x03 pito.srt");
            CreateEmptyFile(path, "TB 1x04 ppito.srt");
        }

        private static void CreateEmptyFile(string path, string fileName)
        {
            try
            {
                using (StreamWriter sw = File.CreateText(path + "\\" + fileName))
                {
                    sw.WriteLine(fileName);
                }
            }
            catch (Exception){}
        }

        private static void ShowHelp()
        {
            Console.WriteLine(st.Get(TEXTO.AYUDA));
        }
        static StringTable st = new StringTable();
    }
}
